var componentTreeAddressBasePath = componentAddressBasePath+"/dhtmlxTree_pro";
var themeTreeAddressBasePath = componentTreeAddressBasePath;
if(themeAddr != '1'){ 
	themeTreeAddressBasePath = 'theme/'+themeAddr+'/dhtmlx-style';
}
document.write('<link rel="stylesheet" type="text/css" href="'+themeTreeAddressBasePath+'/dhtmlxtree.css">');
document.write('<script type="text/javascript" src="'+componentTreeAddressBasePath+'/dhtmlxcommon.js"></script>');
document.write('<script src="'+componentTreeAddressBasePath+'/dhtmlxtree.js"></script>');

var MyTree = {
	tree : null
	//,imagePath : "component/dhtmlx3.5/dhtmlxTree_pro/imgs/csh_vista/"
	,imagePath : (themeAddr != '1' ? (themeTreeAddressBasePath+'/imgs/'):"theme/treeImgs/")
	,xmlURL : null
	,initMyTreeFromLayout : function(layout,layoutcell){
		this.initMyTreeFromLayoutCell(layout.cells(layoutcell));
	}
	,initMyTreeFromLayoutCell : function(cell){
		this.tree = cell.attachTree();
		itemProgressOff(cell);
		this.tree.attachEvent("onXLS", function(grid_obj,count){itemProgressOn(cell);}); 
		this.tree.attachEvent("onXLE", function(grid_obj,count){itemProgressOff(cell);}); 
	}
	,initMyTreeFromTabbar : function(tabbar,tabbarcell){
		 this.tree = tabbar.cells(tabbarcell).attachTree();
	}
	,initMyTreeNormal : function(divId){
		this.tree = new dhtmlXTreeObject(divId, "100%", "100%", 0);
	}
	,setupTree : function(xmlURLParam,clickNode,loadedFunction){
	  	this.xmlURL = xmlURLParam;
		this.tree.setImagePath(this.imagePath);    
		this.tree.loadXML(this.xmlURL,loadedFunction);
		this.tree.setOnClickHandler(clickNode);
	}
	,getMyTree : function(){
		return this.tree;
	}
	,addNode : function (sid, id, text, nodeEvent, nodeImgClose, nodeImgOpen, nodeImgLeaf, options){
		this.tree.insertNewChild(sid, id, text, nodeEvent, nodeImgClose, nodeImgOpen, nodeImgLeaf, options);
	}
	,delNode : function (selectId){
		this.tree.deleteItem(selectId, true);
	}
	,delNodeTop : function (selectId){
		this.tree.deleteItem(selectId);
	}
	,delNodeAll : function (){
		this.tree.deleteChildItems(this.tree.getSelectedItemId());
	}
	,editNode : function (id, txt){
		this.tree.setItemText(id, txt, '');
	}
	,getNodeLevel : function (id){
		return this.tree.getLevel(id);
	}
	,moveUpStrict : function (id){
		this.tree.moveItem(id, "up_strict", "");
	}
	,moveDownStrict : function (id){
		this.tree.moveItem(id, "down_strict", "");
	}
	,changeColor : function (id, fontcolor,backgrFontColor){
		this.tree.setItemColor(id, fontcolor, backgrFontColor);
	}
	,enableCheckBoxes : function(){
		this.tree.enableCheckBoxes(1);
		this.tree.enableThreeStateCheckboxes(true);
	}
	,enableCheckBoxesNoSub : function(){
		this.tree.enableCheckBoxes(1);
	}
	,setCheck : function(id){
		var checkState = this.tree.isItemChecked(id);
		//alert(this.tree.isItemChecked(5));
		if(checkState == 1){
			this.tree.setCheck(id, false);//等于一是已经选中了
		}
		if(checkState == 0){
			this.tree.setCheck(id, true);
		}
	}
	,getAllCheckedId : function(){
		return this.tree.getAllChecked();
	}
	,getAllUncheckedId : function(){
		return this.tree.getAllUnchecked();
	}
	,setXmlAutoLoad : function(xmlUrl){ // 对包含属性child=1的item节点，触发动态加载xml
		this.tree.setXMLAutoLoading(xmlUrl);
	}
	,getUserDataAttr : function(id, attr){ // 获取指定ID的item的子节点userdata的属性attr的值
		return this.tree.getUserData(id, attr);
	}
	,setUserDataAttr : function(id, attr, value){ // 设置指定ID 的item的子节点userdata的属性attr的值
		this.tree.setUserData(id, attr, value);
	}
	,selectNode : function(id){ // 选择节点，并触发点击事件
		this.tree.selectItem(id, true, false);
	}
	,getParentNodeId : function(id){ // 得到父节点id
		return this.tree.getParentId(id);
	}
	,getSelectNodeId : function(){
		return this.tree.getSelectedItemId();
	}
	,getNodeOpenState : function(id){
		return this.tree.getOpenState(id);
	}
	,openNode : function(id){
		this.tree.openItem(id);
	}
	,openAllNode : function(){
		this.tree.openAllItems(0);
	}
	,closeNode : function(id){
		this.tree.closeItem(id);
	}
	,closeAllNode : function(){
		this.tree.closeAllItems(0);
	}
	,refreshNode : function(id){
		this.tree.refreshItem(id);
	}
	,hasChildNode : function(id){
		return this.tree.hasChildren(id);
	}
};